/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY. 
 * See the GNU General Public License for more details.
 * 
 * Copyright (C) 2011 CellObject.net
 */
package net.cellobject.javacodeformatter.editor;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 * A content provider mediates between the viewer's model and the viewer itself. In our case, this content provider extracts
 * property elements to be displayed one per row in the editor.
 */
public class PropertyEditorContentProvider implements ITreeContentProvider {
	public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
	}

	public Object[] getElements(final Object element) {
		return getChildren(element);
	}

	public Object[] getChildren(final Object element) {
		if (element instanceof PropertyElement) {
			return ((PropertyElement)element).getChildren();
		}
		return null;
	}

	public Object getParent(final Object element) {
		if (element instanceof PropertyElement) {
			return ((PropertyElement)element).getParent();
		}
		return null;
	}

	public boolean hasChildren(final Object element) {
		if (element instanceof PropertyElement) {
			return ((PropertyElement)element).getChildren().length > 0;
		}
		return false;
	}

	public void dispose() {
	}
}
